package yyee.llee.mmee.weather.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import yyee.llee.mmee.base_api_net.base_api_bean.bean.FutureInfo
import yyee.llee.mmee.common.databinding.ItemForecast7Binding
import bh.FS

class Forecast7dAdapter(val context: Context, private val datas: List<FutureInfo>) :
    RecyclerView.Adapter<Forecast7dAdapter.ViewHolder>() {

    private var mMin = 0
    private var mMax = 0

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            ItemForecast7Binding.inflate(LayoutInflater.from(context), parent, false)
        )
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = datas[position]

//        val bean = UIUtils.getColorResourceByAirQualityNum(item.aqi.aqi.toInt(), context)

        holder.binding.apply {
            tvWeek.text = FS.getWeekDay(position, item.date)
            tvDate.text = item.date.removeRange(IntRange(0, 4))
            tvDayDesc.text = item.weather
            ivDay.setImageResourceName(item.wid.day)
//            ivNight.setImageResourceName(item.code_night)
//            tvNightDesc.text = item.text_night
//            tvWind.text = item.wd_day
//            tvWindScale.text = item.wc_day
//            tvAqiLevels.text = (bean.status)
//            tvAqiLevels.setTextColor(bean.color)
//            tvAqiLevels.setBackgroundResource(bean.bgResource)

            tempChart.setData(
                mMin,
                mMax,
                if (position == 0) null else datas[position - 1], item,
                if (position == datas.size - 1) null else datas[position + 1]
            )
        }
    }


    override fun getItemCount(): Int = datas.size

    fun setRange(min: Int, max: Int) {
        mMin = min
        mMax = max
        notifyDataSetChanged()
    }

    class ViewHolder(val binding: ItemForecast7Binding) : RecyclerView.ViewHolder(binding.root)
}